package com.example.springboot.controller;


import com.example.springboot.common.Result;
import com.example.springboot.service.SystemNoticeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统公告表(SystemNotice)表控制层
 *
 * @author makejava
 * @since 2024-01-28 14:47:39
 */
@RestController
@RequestMapping("/systemNotice")
public class SystemNoticeController {
    /**
     * 服务对象
     */
    @Resource
    private SystemNoticeService systemNoticeService;

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @PostMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody List<Integer> ids) {
        systemNoticeService.deleteByIds(ids);
        return Result.success("删除成功！");
    }

    /**
     * 添加公告
     *
     * @param systemNotice
     * @return
     */
    @PostMapping("/addSystemNotice")
    public Result addSystemNotice(@RequestBody SystemNotice systemNotice) {
        systemNoticeService.addSystemNotice(systemNotice);
        return Result.success();
    }

    /**
     * 条件查询
     *
     * @param title
     * @param content
     * @param publisher
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("/selectByManyConditionInPage")
    public Result selectByManyConditionInPage(
            @RequestParam("currentPage") Integer currentPage,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam("title") String title,
            @RequestParam("content") String content,
            @RequestParam("publisher") String publisher,
            @RequestParam("startTime") String startTime,
            @RequestParam("endTime") String endTime) {
        return Result.success(systemNoticeService.selectByManyConditionInPage(currentPage, pageSize, title, content, publisher, startTime, endTime));
    }


    /**
     * 获取所有的系统公告信息
     *
     * @return
     */
    @GetMapping("/selectAll")
    public Result selectAll() {
        return Result.success(systemNoticeService.selectAll());
    }


    /**
     * 获取最新的五条系统公告信息
     *
     * @return
     */
    @GetMapping("/latest")
    public Result selectLatest() {
        return Result.success(systemNoticeService.selectLatest());
    }


    /**
     * 分页查询
     *
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/selectByPage")
    public Result selectByPage(@RequestParam("currentPage") Integer currentPage,
                               @RequestParam("pageSize") Integer pageSize) {
        return Result.success(systemNoticeService.selectByPage(currentPage, pageSize));
    }


    /**
     * 根据ID删除系统公告信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        systemNoticeService.deleteById(id);
        return Result.success("删除成功!");
    }


    /**
     * 更新公告信息
     *
     * @param systemNotice
     * @return
     */
    @PutMapping("/updateById")
    public Result updateById(@RequestBody SystemNotice systemNotice) {
        systemNoticeService.updateById(systemNotice);
        return Result.success("更新成功！");
    }

}

